/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.icee.myth.protobuf.builder;

import com.icee.myth.common.protobufMessage.ProtobufMessage;
import com.icee.myth.common.protobufMessage.ProtobufMessageType;
import com.icee.myth.protobuf.ConsoleToManagerProtocol;
import com.icee.myth.protobuf.ConsoleToManagerProtocol.ServerStatus;
import com.icee.myth.protobuf.ConsoleToManagerProtocol.ServerStatuses;
import com.icee.myth.protobuf.ExternalCommonProtocol.IntValueProto;
import com.icee.myth.protobuf.ExternalCommonProtocol.IntValuesProto;
import com.icee.myth.protobuf.ExternalCommonProtocol.LongValueProto;
import com.icee.myth.protobuf.ExternalCommonProtocol.VariableValueProto;
import com.icee.myth.protobuf.ExternalCommonProtocol.VariableValuesProto;

import java.util.ArrayList;

/**
 * @author liuxianke
 */
public class ConsoleToManagerBuilder {

    public static ProtobufMessage buildServerStartOK(int serverId) {
        IntValueProto.Builder builder = IntValueProto.newBuilder();
        builder.setValue(serverId);

        return new ProtobufMessage(ProtobufMessageType.MANAGER2CONSOLE_SERVER_START_OK, builder.build());
    }

    public static ProtobufMessage buildServerShutdownOK(int serverId) {
        IntValueProto.Builder builder = IntValueProto.newBuilder();
        builder.setValue(serverId);

        return new ProtobufMessage(ProtobufMessageType.MANAGER2CONSOLE_SERVER_SHUTDOWN_OK, builder.build());
    }

    public static ProtobufMessage buildSyncConfigReturn(int result) {
        IntValueProto.Builder builder = IntValueProto.newBuilder();
        builder.setValue(result);

        return new ProtobufMessage(ProtobufMessageType.MANAGER2CONSOLE_SYNCCONFIG_RETURN, builder.build());
    }

    public static ProtobufMessage buildGetServerStatusReturn(int[][] statuses) {
        ServerStatuses.Builder builder = ServerStatuses.newBuilder();

        int serverNum = statuses.length;
        for (int i = 0; i < serverNum; i++) {
            ServerStatus.Builder builder1 = ServerStatus.newBuilder();
            builder1.setId(statuses[i][0]);
            builder1.setStatus(statuses[i][1]);

            builder.addStatuses(builder1);
        }

        return new ProtobufMessage(ProtobufMessageType.MANAGER2CONSOLE_GET_SERVER_STATUS_RETURN, builder.build());
    }

    public static ProtobufMessage buildForceSetServerShutdownStatusOK(int serverId) {
        IntValueProto.Builder builder = IntValueProto.newBuilder();
        builder.setValue(serverId);

        return new ProtobufMessage(ProtobufMessageType.MANAGER2CONSOLE_FORCE_SET_SERVER_SHUTDOWN_STATUS_OK, builder.build());
    }

    public static ProtobufMessage buildForceSetServerShutdownStatusError(int serverId) {
        IntValueProto.Builder builder = IntValueProto.newBuilder();
        builder.setValue(serverId);

        return new ProtobufMessage(ProtobufMessageType.MANAGER2CONSOLE_FORCE_SET_SERVER_SHUTDOWN_STATUS_ERROR, builder.build());
    }

    public static ProtobufMessage buildLoadServerConfigError(int serverId, int errorCode) {
        VariableValueProto.Builder builder = VariableValueProto.newBuilder();
        builder.setId(serverId);
        builder.setValue(errorCode);

        return new ProtobufMessage(ProtobufMessageType.MANAGER2CONSOLE_LOAD_SERVER_CONFIG_ERROR, builder.build());
    }

    public static ProtobufMessage buildLoadServerConfigOK(int serverId) {
        IntValueProto.Builder builder = IntValueProto.newBuilder();
        builder.setValue(serverId);

        return new ProtobufMessage(ProtobufMessageType.MANAGER2CONSOLE_LOAD_SERVER_CONFIG_OK, builder.build());
    }

    public static ProtobufMessage buildBattleWinRateResult(IntValuesProto winRateResult) {
        return new ProtobufMessage(ProtobufMessageType.MANAGER2CONSOLE_BATTLE_WIN_RATE_RESULT, winRateResult);
    }

    public static ProtobufMessage buildCardDrawRateResult(VariableValuesProto cardDrawRateResult) {
        return new ProtobufMessage(ProtobufMessageType.MANAGER2CONSOLE_CARD_DRAW_RATE_RESULT, cardDrawRateResult);
    }

    public static ProtobufMessage buildUninitOccupyInfo(IntValuesProto intValuesProto) {
        return new ProtobufMessage(ProtobufMessageType.MANAGER2CONSOLE_UNINIT_OCCUPY_INFO, intValuesProto);
    }

    public static ProtobufMessage buildFightingOccupyInfo(IntValuesProto intValuesProto) {
        return new ProtobufMessage(ProtobufMessageType.MANAGER2CONSOLE_FIGHTING_OCCUPY_INFO, intValuesProto);
    }

    public static ProtobufMessage buildDateTime(long currentTime) {
        LongValueProto.Builder builder = LongValueProto.newBuilder();
        builder.setValue(currentTime);

        return new ProtobufMessage(ProtobufMessageType.MANAGER2CONSOLE_DATE_TIME, builder.build());
    }

    //region console服务器用的
    public static ProtobufMessage buildRunServer(int serverId) {
        IntValueProto.Builder builder = IntValueProto.newBuilder();
        builder.setValue(serverId);

        return new ProtobufMessage(ProtobufMessageType.CONSOLE2MANAGER_RUN_SERVER, builder.build());
    }

    public static ProtobufMessage buildShutdownServer(int serverId) {
        IntValueProto.Builder builder = IntValueProto.newBuilder();
        builder.setValue(serverId);

        return new ProtobufMessage(ProtobufMessageType.CONSOLE2MANAGER_SHUTDOWN_SERVER, builder.build());
    }

    public static ProtobufMessage buildSyncConfig() {
        return new ProtobufMessage(ProtobufMessageType.CONSOLE2MANAGER_SYNCCONFIG, null);
    }

    public static ProtobufMessage buildGetServerState() {
        return new ProtobufMessage(ProtobufMessageType.CONSOLE2MANAGER_GET_SERVER_STATUS, null);
    }

    public static ProtobufMessage buildDebugRunServer(int serverId) {
        IntValueProto.Builder builder = IntValueProto.newBuilder();
        builder.setValue(serverId);

        return new ProtobufMessage(ProtobufMessageType.CONSOLE2MANAGER_DEBUG_RUN_SERVER, builder.build());
    }

    public static ProtobufMessage buildGm(ArrayList<String> strArgs) {
        ConsoleToManagerProtocol.C2MGmProto.Builder builder = ConsoleToManagerProtocol.C2MGmProto.newBuilder();
        int serverId = Integer.valueOf(strArgs.get(0));
        int playerId = Integer.valueOf(strArgs.get(1));
        String gmCmd = strArgs.get(2);

        builder.setServerId(serverId);
        builder.setPlayerId(playerId);
        builder.setGmCmd(gmCmd);
        System.out.printf("ServerId=%d,PlayerId=%d,GmCmd=%s!!", serverId, playerId, gmCmd);

        for (int i = 3; i < strArgs.size(); i++) {
            String s = strArgs.get(i);
            builder.addArgs(s);
            System.out.printf("strArgs[%d]=%s,", i, s);
        }
        System.out.printf("\n");

        return new ProtobufMessage(ProtobufMessageType.CONSOLE2MANAGER_GM, builder.build());
    }

    public static ProtobufMessage buildClearTestFlag(int serverId) {
        IntValueProto.Builder builder = IntValueProto.newBuilder();
        builder.setValue(serverId);

        return new ProtobufMessage(ProtobufMessageType.CONSOLE2MANAGER_CLEAR_TEST_FLAG, builder.build());
    }

    public static ProtobufMessage buildSetTestFlag(int serverId) {
        IntValueProto.Builder builder = IntValueProto.newBuilder();
        builder.setValue(serverId);

        return new ProtobufMessage(ProtobufMessageType.CONSOLE2MANAGER_SET_TEST_FLAG, builder.build());
    }

    public static ProtobufMessage buildForceSetServerShutdownStatus(int serverId) {
        IntValueProto.Builder builder = IntValueProto.newBuilder();
        builder.setValue(serverId);

        return new ProtobufMessage(ProtobufMessageType.CONSOLE2MANAGER_FORCE_SET_SERVER_SHUTDOWN_STATUS, builder.build());
    }

    public static ProtobufMessage buildLoadServerConfig(int serverId) {
        IntValueProto.Builder builder = IntValueProto.newBuilder();
        builder.setValue(serverId);

        return new ProtobufMessage(ProtobufMessageType.CONSOLE2MANAGER_LOAD_SERVER_CONFIG, builder.build());
    }

    public static ProtobufMessage buildSetDate(long date) {
        LongValueProto.Builder builder = LongValueProto.newBuilder();
        builder.setValue(date);

        return new ProtobufMessage(ProtobufMessageType.CONSOLE2MANAGER_SET_SYSTEM_DATE, builder.build());
    }

    public static ProtobufMessage buildSetTime(long time) {
        LongValueProto.Builder builder = LongValueProto.newBuilder();
        builder.setValue(time);

        return new ProtobufMessage(ProtobufMessageType.CONSOLE2MANAGER_SET_SYSTEM_TIME, builder.build());
    }

    public static ProtobufMessage buildGetDateTime() {
        return new ProtobufMessage(ProtobufMessageType.CONSOLE2MANAGER_GET_SYSTEM_DATETIME, null);
    }
    //endregion console服务器用的

}
